import 'package:get/get.dart';

/// Created by XieXin on 2022/8/19.
/// 全局控制器
///
/// 发送
/// final GlobalController globalController = Get.find<GlobalController>();
/// globalController.code.value = EventEntity.mainTabIndex0;
/// globalController.event.value = EventEntity(EventEntity.mainTabIndex0);
///
/// 监听
///     ever<int>(globalController.code, (value) {
///       switch (value) {
///         case EventEntity.mainTabIndex0:
///           setTabIndex(0);
///           break;
///         case EventEntity.mainTabIndex1:
///           setTabIndex(1);
///           break;
///         case EventEntity.mainTabIndex2:
///           setTabIndex(2);
///           break;
///         case EventEntity.mainTabIndex3:
///           setTabIndex(3);
///           break;
///       }
///     });
///
///    ever<EventEntity>(globalController.event, (value) {
///       switch (value.code) {
///         case EventEntity.mainTabIndex0:
///           setTabIndex(0);
///           break;
///         case EventEntity.mainTabIndex1:
///           setTabIndex(1);
///           break;
///         case EventEntity.mainTabIndex2:
///           setTabIndex(2);
///           break;
///         case EventEntity.mainTabIndex3:
///           setTabIndex(3);
///           break;
///       }
///
///  ever 当数据发生改变时触发
///  everAll 和 “ever “很像，只是监听的是多个响应式变量的变化，当其中一个发生变化就会触发回调
///  once 只在变量第一次被改变时被调用
///  debounce 防抖，即延迟一定时间调用，且在规定时间内只有最后一次改变会触发回调。如设置时间为 1 秒，发生了3次数据变化，每次间隔500毫秒，则只有最后一次变化会触发回调。
///  interval 时间间隔内只有最后一次变化会触发回调。如设置时间间隔为1秒，则在1秒内无论点击多少次都只有最后一次会触发回调，然后进入下一次的时间间隔。
///
class GlobalController extends GetxController {
  var event = EventEntity(-1).obs;
}

class EventEntity<T> {
  int code;
  String? msg;
  T? arguments;

  EventEntity(this.code, {this.msg, this.arguments});

  ///-/////////////////////////////////////////////////////////////////////////
  ///100开头公共模块
  ///主页tabIndex=0
  static const int mainTabIndex0 = 100000;

  ///主页tabIndex=1
  static const int mainTabIndex1 = 100001;

  ///主页tabIndex=2
  static const int mainTabIndex2 = 100002;

  ///主页tabIndex=3
  static const int mainTabIndex3 = 100003;

  ///-/////////////////////////////////////////////////////////////////////////
  ///200开头账户模块
  ///登录
  static const int accountLogin = 200000;
}
